<%-- 
    Document   : ClientDetail
    Created on : 12/Jan/2010, 22:33:01
    Author     : Marco
--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${requestScope['title']} - ${requestScope['action']}</title>
        <style type="text/css">
            body { font-family: Verdana, sans-serif; font-size:80%}
            table {
                border-color:black;
                border-style:solid;
                border-width:thin;
                padding:0;
                margin:0;
            }
            tr.l1 {
                background:lightblue;
                padding:0;
                margin:0;
            }
            tr.l2 {
                padding:0;
                margin:0;
            }
            .error {
                border-color:red;
                border-style:solid;
                border-width:thin;
            }
        </style>
    </head>
    <body>
        <h1>${requestScope['title']} - ${requestScope['action']}</h1>
        <form action="?action=${requestScope['formMethod']}" method="POST">
            <c:choose>
                <c:when test="${!empty requestScope['client']}">
                    <input type="hidden" name="clientId" value="${requestScope['client'].id}" />
                </c:when>
            </c:choose>
            <table>
                <tbody>
                    <tr>
                        <td>Nome :</td>
                        <td><input type="text" name="name" value="${requestScope['client'].name}" maxlength="40" ${requestScope['editable']} /></td>
                    </tr>
                    <tr>
                        <td>NIF/NIPC :</td>
                        <td><input type="text" name="nif" value="${requestScope['client'].nif}" maxlength="12" ${requestScope['editable']} /></td>
                    </tr>
                    <tr>
                        <td>Morada :</td>
                        <td><input type="text" name="address" value="${requestScope['client'].address}" maxlength="40" ${requestScope['editable']} /></td>
                    </tr>
                    <tr>
                        <td>Código Postal :</td>
                        <td><input type="text" name="town" value="${requestScope['client'].town}" maxlength="40" ${requestScope['editable']} /></td>
                    </tr>
                    <tr>
                        <td>Telefone :</td>
                        <td><input type="text" name="phone" value="${requestScope['client'].phone}" maxlength="15" ${requestScope['editable']} /></td>
                    </tr>
                    <tr>
                        <td>Email :</td>
                        <td><input type="text" name="email" value="${requestScope['client'].email}" maxlength="45" ${requestScope['editable']} /></td>
                    </tr>
                    <c:choose>
                        <c:when test="${requestScope['formMethod'] == 'save'}">
                            <tr>
                                <td>Código Balcão :</td>
                                <td><input type="text" name="agency" value="${requestScope['account'].agency}" maxlength="4" ${requestScope['editable']} /></td>
                            </tr>
                        </c:when>
                    </c:choose>
                    <tr>
                        <c:choose>
                            <c:when test="${requestScope['formMethod'] == 'save' || requestScope['formMethod'] == 'update'}">
                                <td><input type="submit" value="Gravar" /></td>
                                    <c:choose>
                                        <c:when test="${requestScope['formMethod'] == 'update'}">
                                        <td><input type="button" value="Cancelar" onclick="this.form.action='?action=detail'; this.form.submit();"/></td>
                                        </c:when>
                                        <c:otherwise>
                                        <td><input type="button" value="Cancelar" onclick="this.form.action='?'; this.form.submit();"/></td>
                                        </c:otherwise>
                                    </c:choose>
                                </c:when>
                                <c:otherwise>
                                <td><input type="button" value="Editar" onclick="this.form.action='?action=edit'; this.form.submit();"/></td>
                                <td><input type="button" value="Voltar" onclick="this.form.action='?'; this.form.submit();"/></td>
                                </c:otherwise>
                            </c:choose>
                    </tr>
                </tbody>
            </table>
                    <br/><br/>
            <c:choose>
                <c:when test="${!empty requestScope['client'] && requestScope['formMethod']=='detail'}">
                    <input type="hidden" name="accountId" value="" />
                    <table>
                        <thead>
                            <tr>
                                <th>Balcão</th>
                                <th>Nº Conta</th>
                                <th>Saldo Cont.</th>
                                <th>Saldo Disp.</th>
                                <td colspan="2"><input type="button" value="Abrir Conta" onclick="this.form.action='account?action=new'; this.form.submit();"/></td>
                            </tr>
                        </thead>
                        <c:choose>
                            <c:when test="${!empty requestScope['accounts']}">
                                <tbody>
                                    <c:forEach var="account" items="${requestScope['accounts']}" varStatus="loop">
                                        <tr class="${loop.index % 2 == 0 ? 'l1' : 'l2'}">
                                            <td>${account.agency}</td>
                                            <td>${account.number}</td>
                                            <td>${account.accountingBalance} &euro;</td>
                                            <td>${account.availableBalance} &euro;</td>
                                            <td><input type="button" value="Detalhes" onclick="this.form.action='account?action=detail'; this.form.accountId.value=${account.id}; this.form.submit();"/></td>
                                            <td><input type="button" value="Movimentos" onclick="this.form.action='account?action=movements'; this.form.accountId.value=${account.id}; this.form.submit();"/></td>
                                        </tr>
                                    </c:forEach>
                                </tbody>
                            </c:when>
                        </c:choose>
                    </table>
                </c:when>
            </c:choose>
        </form>
        <br/>
        <c:choose>
            <c:when test="${!empty(requestScope['formError'])}">
                <div class="error">${requestScope['formError']}</div>
            </c:when>
        </c:choose>
    </body>
</html>
